package mobi.pruss.multiuser;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.AdapterView.OnItemClickListener;

public class Apps extends Activity {
	ArrayList<String> users;
	ListView appsList;
	Resources res;
	final static String PREF_APPS = "apps";

	public void onClickUsers(View v) {
		startActivity(new Intent(this, Users.class));
	}
	
	public void activateApp(MyApplicationInfo appInfo) {
		Log.v("activate", appInfo.packageName);
		SharedPreferences.Editor ed = getSharedPreferences(PREF_APPS, 0).edit();
		ed.putBoolean(appInfo.packageName, true);
		ed.commit();
	}
	
	public void deactivateApp(MyApplicationInfo appInfo) {		
		Log.v("deactivate", appInfo.packageName);
		SharedPreferences.Editor ed = getSharedPreferences(PREF_APPS, 0).edit();
		ed.remove(appInfo.packageName);
		ed.commit();
	}	

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.apps);
        
        appsList = (ListView)findViewById(R.id.apps);
        
        res = getResources();        
        users = Users.getUsers(this);

        appsList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
	}
	
    @Override
    public void onStart() {
    	super.onStart();

        (new GetApps(this, appsList, (ProgressBar)findViewById(R.id.progress))).execute();
    }
}

